package io.github.talelin.latticy.core.configuration;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ElasticsearchClient {

    @Value("${elasticsearch.ip}")
    String ipAddress;

    @Value("${elasticsearch.port}")
    Integer port;

    @Bean(name="highLevelClient")
    public RestHighLevelClient highLevelClient(){
        //分割IP地址
        //指定IP端口协议
        HttpHost httpHost = new HttpHost(this.ipAddress,this.port,"http");
        return new RestHighLevelClient(RestClient.builder(httpHost));
    }
}